package com.lhd.weibo.controller;

import com.lhd.weibo.pojo.dto.UserLoginDTO;
import com.lhd.weibo.pojo.dto.UserRegDTO;
import com.lhd.weibo.pojo.entity.User;
import com.lhd.weibo.pojo.vo.UserVO;
import com.lhd.weibo.response.JsonResult;
import com.lhd.weibo.response.StatusCode;
import com.lhd.weibo.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

import static com.lhd.weibo.response.StatusCode.LOGIN_SUCCESS;

/**
 * @author lhd
 * date 2024/5/15
 * @apiNote
 */
@RestController()
@Slf4j
@RequestMapping(value ="/v1/users")
public class UserController {

    @Autowired
    private UserService userService;
    @PostMapping(value ="/reg")
    public JsonResult reg(UserRegDTO userRegDTO) {
        log.info("注册 对象 userRegDTO = " + userRegDTO);
        System.out.println("username = " + userRegDTO.getUsername() + ", password = " + userRegDTO.getPassword() + ", nickname = " + userRegDTO.getNickname());
        // 控制层不再设计业务 只需要调用业务层
        userService.reg(userRegDTO);

        return JsonResult.ok();
    }

    @PostMapping(value ="/login")
    public JsonResult login(UserLoginDTO userLoginDTO){
        log.info("登录 对象 userLoginDTO = " + userLoginDTO);

        UserVO userVO = userService.login(userLoginDTO);
        return new JsonResult(LOGIN_SUCCESS, userVO);
    }
}
